﻿namespace DotRas
{
    using System;
    using System.Runtime.Serialization;
    using System.Security.Permissions;

    [Serializable]
    public class RasException : Exception
    {
        private int _errorCode;

        public RasException()
        {
        }

        public RasException(int errorCode) : base(RasHelper.GetRasErrorString(errorCode))
        {
            this._errorCode = errorCode;
        }

        public RasException(string message) : base(message)
        {
        }

        protected RasException(SerializationInfo info, StreamingContext context) : base(info, context)
        {
            this._errorCode = (int) info.GetValue("ErrorCode", typeof(int));
        }

        public RasException(string message, Exception innerException) : base(message, innerException)
        {
        }

        [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.SerializationFormatter)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            if (info != null)
            {
                info.AddValue("ErrorCode", this._errorCode, typeof(int));
            }
            base.GetObjectData(info, context);
        }

        public int ErrorCode
        {
            get
            {
                return this._errorCode;
            }
        }
    }
}

